require(['validator'], function() {
		var $severityForm = $("#severityForm"),
		seleOrganId = "",corpId = "";

		$("#severityBnt").hide();

		//左侧树点击事件
		commonFun.leftTreeNodeClickObj['sysSeverityParamSet'] = function(event, treeId, treeNode) {
			if(treeNode.type === 'CAR' || treeNode.type === 'DRIVER'){
				$.messager.alert("提示","请选择组织机构或线路，进行参数设置。","info");
				return;
			}
			seleOrganName = treeNode.name;
			seleOrganId = treeNode.id;
			corpId = treeNode.corpId;
			showInterface();
		};

		//根据后台返回的数据，动态生成界面
		var showInterface = function(){
			$.ajaxExt({
				url : "/severity/searchSeverityInfo.htm",
				data : {"corpId":corpId, "organId":seleOrganId}
			}).done(function(data){
				if(data){
					var currData = data;
					$severityForm.empty();
					$("#severityBnt").show();
					var flag1 = 0,
						flag2 = 0,
						flag3 = 0,
						currOrganId = currData[0].organId,
						content = "";	 
					$severityForm.append("<div class='user-info-wrap score-setting'></div>");
					$severityForm.find(".user-info-wrap").append("<h1 class='line-title'>【"+seleOrganName+"】的严重度设置信息</h1>");
					$severityForm.find(".user-info-wrap").append(
				  			"<input type='hidden' name='corpId' value='"+corpId+"'/>"
				 			+"<input type='hidden' name='seleOrganId' value='"+seleOrganId+"'/>"
							+"<input type='hidden' name='currOrganId' value='"+currOrganId+"'/>");
					$.each(currData,function(n,entity){
						content = "<li>"
						+"<label class='label-text label-require'>"+entity.paramName+"的范围：</label>"
						+"<input type='hidden' name='paramIds' value='"+entity.paramId+"'/>"
						+"<input  class='input-text' type='text' name='paramValues' class='u-input' data-validator='{required:true}' value='"+entity.paramValue+"'/>  <label class='vm mr2'>~</label> "
						+"<input  class='input-text' type='text' name='paramValue2s' class='u-input' data-validator='{required:true}' value='"+entity.paramValue2+"'/>"
						+"</li>";
						if(entity.paramTypeCode == 'PARA0100'){
							if(flag1 == 0){
								$severityForm.find(".user-info-wrap").append("<div class='user-info-box'><h2 class='title-style1 mt20'><span>超速严重度设置(%)</h2>"
								+"<div class='mt30 pr-s'><ul class='form-grid form-grid2 form-grid2-nowrap  clearfix'  id ='PARA0100'>"
								+"</ul></div>"
								+"</div>");
								flag1 = 1;
							}
							$("#PARA0100").append(content);
						}
						if(entity.paramTypeCode == 'PARA0200'){
							if(flag2 == 0){
								$severityForm.find(".user-info-wrap").append("<div>"
								+"<div class='user-info-box'><h2 class='title-style1 mt20'><span>违章扣分范围设置(次)</h2>"
								+"<div class='mt30 pr-s'><ul  class='form-grid form-grid2 form-grid2-nowrap clearfix' id = 'PARA0200'>"
								+"</ul></div>"
								+"</div>");
								flag2 = 1;
							}
							$("#PARA0200").append(content);
						}
						if(entity.paramTypeCode == 'PARA0300'){
							if(flag3 == 0){
								$severityForm.find(".user-info-wrap").append("<div>"
								+"<div class='user-info-box'><h2 class='title-style1 mt20'><span>事故发生金额范围设置(元)</h2>"
								+"<div class='mt30 pr-s'><ul class='form-grid  form-grid2 form-grid2-nowrap  clearfix' id = 'PARA0300'>"
								+"</ul></div>"
								+"</div>");
								flag3 = 1;
							}
							$("#PARA0300").append(content);
						}
					});
					$severityForm.find(".user-info-wrap").append(
							"<div class='user-btn-box' id='severityBnt'>"+
							"<a href='javascript:;' class='btn btn-save btn-medium' onclick='severity_update()'>保存</a>"+
						    "<a href='javascript:;' class='btn btn-cancel btn-medium' onclick='severity_reset()' >重置</a>"+
							"</div>"
					);
				}else{
					$severityForm.html("无数据。");
					$("#severityBnt").hide();
				}
			});
		};


		severity_reset = function(){
			showInterface();
		};
		
		severity_update = function(){
			if($.validator($severityForm)){
				$.messager.confirm("是否修改","确定修改该机构所对应的严重度参数？",function(r){
					if(r){
						var formData = $severityForm.serializeArray();
						$.ajaxExt({
							url : "/severity/uptSeverityInfo.htm",
							data : formData
						}).done(function(data){
							$.messager.alert("提示","您成功修改了该机构所对应的严重度参数。","success");
						});
					}
				});
			}
		};
});